package dao

import (
	"micro.user.server/database"
	"micro.user.server/models"
	"time"
)

func CreateHotelUser(users []*models.VsHUser) error {
	_, err := database.GetDB().Table("vs_h_user").Insert(users)
	return err
}

func UsrList(hotelID uint64, userIDList interface{}) ([]models.VsHUser, error) {
	users := make([]models.VsHUser, 0)

	if err := database.GetDB().Where("is_delete = ? and hotel_id = ?", 0, hotelID).In("user_id", userIDList).Find(&users); err != nil {
		return nil, err
	}

	return users, nil
}

func UpdateUser(user models.VsHUser) error {
	if _, err := database.GetDB().Where("user_id = ? and is_delete = 0", user.UserId).Update(&user); err != nil {
		return err
	}

	return nil
}

func DeleteUser(userIDList []interface{}) error {
	database.GetDB().ShowSQL(true)
	if _, err := database.GetDB().Table("vs_h_user").Where("is_delete = 0").In("user_id", userIDList...).Update(map[string]interface{}{"is_delete": 1, "updated_time": time.Now().Unix()}); err != nil {
		return err
	}
	return nil
}
